package com.easy.service.impl;

import com.easy.bean.Supplier;
import com.easy.mapper.SupplierDao;
import com.easy.service.SupplierService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    @Override
    public Supplier add(Supplier supplier) {
        if (supplier.getIs_deleted() == null) {
            supplier.setIs_deleted((byte)0); // 默认未删除
        }
        supplierDao.add(supplier);
        return supplierDao.one(supplier.getId());
    }

    @Override
    public int del(Integer id) {
        return supplierDao.del(id);
    }

    @Override
    public Supplier edit(Supplier supplier) {
        supplierDao.edit(supplier);
        return supplierDao.one(supplier.getId());
    }

    @Override
    public List<Supplier> all(String name) {
        return supplierDao.all(name);
    }

    @Override
    public Supplier one(Integer id) {
        return supplierDao.one(id);
    }

    @Override
    public void page(Page page, Supplier supplier) {
        int count = supplierDao.pageCount(supplier);
        List<Supplier> data = supplierDao.page(page, supplier);
        page.setCount(count);
        page.setData(data);
    }
}
